Skip to content

Log exception for HF whoami username resolution failure#219

Open
Goodnight77 wants to merge 2 commits intohuggingface:mainfrom
Goodnight77:log-hf-whoami-failures
Open

Log exception for HF whoami username resolution failure#219
Goodnight77 wants to merge 2 commits intohuggingface:mainfrom
Goodnight77:log-hf-whoami-failures

Conversation

@Goodnight77
Copy link
Copy Markdown
Contributor

summary

  • _get_hf_user in agent/main.py swallowed all exceptions silently
  • added module logger and logger.exception call so the traceback is recorded before the function falls back to None

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 6, 2026

Claude finished @lewtun's task in 1m 22s —— View job


Review

No blocking issues — 1 P2.

The diff is the minimal, correct change for the stated goal: replace silent except: return None with a logged-then-fallback. Function still returns None so the banner path (agent/main.py:985, agent/main.py:1225) is unaffected. No token value is included in the log message, only the description — no secret leakage.

P2: Severity vs. existing pattern in agent/context_manager/manager.py

The other whoami helper in this repo, _get_hf_username at agent/context_manager/manager.py:24, treats whoami failures as logger.warning (e.g. manager.py:63, manager.py:36) — non-fatal degradation, fall back to "unknown". This PR uses logger.exception (ERROR + traceback) for the same class of failure.

Both are defensible — HfApi().whoami() can raise a wider range of exceptions than the curl-based path, so a traceback has more debugging value here. But two notes worth considering:

  1. In interactive mode (cli() at agent/main.py:1414), no basicConfig is called, so an ERROR record falls through to Python's lastResort handler and prints the full traceback to stderr immediately before print_banner runs (agent/main.py:987). On a transient network blip this will produce a multi-line traceback right before the welcome banner. logger.warning("HF whoami failed: %s", exc) (or logger.warning(..., exc_info=True)) would be quieter while still capturing the error — and consistent with the sibling helper.
  2. Headless mode (agent/main.py:1203) uses basicConfig(level=WARNING), so either ERROR or WARNING surfaces there — the choice only affects interactive UX.

Not blocking. The author may reasonably prefer the full traceback; if so, leaving as-is is fine.


· Branch: log-hf-whoami-failures

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants